using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace Money_Log_Mobile
{
    public partial class Form1 : Form
    {
        private const string Filename = "";
        private Bank oBank;
        public Form1()
        {
            InitializeComponent();
            oBank = new Bank(Filename);
        }
        protected override void OnActivated(EventArgs e)
        {
            base.OnActivated(e);
            UpdateDataGrid();
        }
        private void menuItem1_Click(object sender, EventArgs e)
        {
            frmAddTransaction ofrmAddTransaction = new frmAddTransaction(oBank);
            ofrmAddTransaction.Show();
        }
        private void UpdateDataGrid()
        {
            DataTable dttransactions = new DataTable();
            dttransactions.Columns.Add("ID");
            
            dttransactions.Columns.Add("Name");
            dttransactions.Columns.Add("Amount");
            dttransactions.Columns.Add("Date");
            foreach (Transaction otransation in oBank.TransactionList)
            {
                DataRow drtransaction = dttransactions.NewRow();
                drtransaction["ID"] = otransation.TransactionID;
                drtransaction["Name"] = otransation.Name;
                drtransaction["Amount"] = otransation.Amount;
                drtransaction["Date"] = otransation.Date;
                dttransactions.Rows.Add(drtransaction);
            }
            dataGrid1.DataSource = dttransactions;
        }

        private void menuItem4_Click(object sender, EventArgs e)
        {
            frmStandingOrder ofrmStandingOrder = new frmStandingOrder(oBank);
            ofrmStandingOrder.Show();
        }

        private void menuSave_Click(object sender, EventArgs e)
        {
            oBank.Save();
        }

        private void menuItem1_Click_1(object sender, EventArgs e)
        {
            notification1.Text = "text";
            notification1.Visible = true;
            notification1.Caption = "Money Log Mobile";
            notification1.Critical = true;
        }

        private void contextMenu1_Popup(object sender, EventArgs e)
        {
            //contextMenu1.MenuItems.Clear();
            //MenuItem i = new MenuItem();
            //i.Text = "test";
            //contextMenu1.MenuItems.Add(i);
        }

        private void menuItem3_Click(object sender, EventArgs e)
        {
            DataTable dtgrid = (DataTable)dataGrid1.DataSource;
            int SelectedTransactionID = Convert.ToInt32(dtgrid.Rows[dataGrid1.CurrentRowIndex]["ID"]);
            oBank.DeleteTransaction(SelectedTransactionID);
            UpdateDataGrid();
        }

        private void Form1_KeyDown(object sender, KeyEventArgs e)
        {
            if ((e.KeyCode == System.Windows.Forms.Keys.Up))
            {
                // Up
            }
            if ((e.KeyCode == System.Windows.Forms.Keys.Down))
            {
                // Down
            }
            if ((e.KeyCode == System.Windows.Forms.Keys.Left))
            {
                // Left
            }
            if ((e.KeyCode == System.Windows.Forms.Keys.Right))
            {
                // Right
            }
            if ((e.KeyCode == System.Windows.Forms.Keys.Enter))
            {
                // Enter
                frmStandingOrder ofrmStandingOrder = new frmStandingOrder(oBank);
                ofrmStandingOrder.Show();
            }

        }

    }
}